package com.calciominoBeta.Activity;

import java.util.ArrayList;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.calciominoBeta.R;
import com.calciominoBeta.Entity.InfoOj;
import com.calciominoBeta.Util.Sdata;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.telpoo.frame.utils.Mlog;

public class AQDetailActivity extends FragmentActivity {

	protected ImageLoader imageLoader = ImageLoader.getInstance();
	protected DisplayImageOptions options;
	private ImageView img_next, img_prev, img_back, img_share, img_share_post;
	ArrayList<InfoOj> dataLv = null;
	Integer position = 1;
	ListView lv_accueil;
	protected int itemHeight;
	private AdView adView;
	private ViewPager viewPager;
	NgPageViewAdapter adapter;
	ProgressDialog progressDialog;
	int temcurepare=0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail);

		dataLv = Sdata.dataLv;
		position = Sdata.position;
		Sdata.dataLv = null;
		Sdata.position = null;
		img_next = (ImageView) findViewById(R.id.img_next);
		img_prev = (ImageView) findViewById(R.id.img_prev);
		viewPager = (ViewPager) findViewById(R.id.pager_container_web);
		viewPager.setOffscreenPageLimit(3);
		img_back = (ImageView) findViewById(R.id.img_back);
		
		FragmentManager fragmentManager = getSupportFragmentManager();
		adapter = new NgPageViewAdapter(fragmentManager, dataLv,
				getBaseContext());
		viewPager.setAdapter(adapter);

		adView = (AdView) findViewById(R.id.ad);
		AdRequest adRequest = new AdRequest.Builder()
				.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("")
				.build();
		adView.loadAd(adRequest);

		img_next.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, true);
			}

		});
		img_prev.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, true);

			}
		});
		img_back = (ImageView) findViewById(R.id.img_back);
		img_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});
		
		viewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				//DemoScorllPauseVd demoScorllPauseVd = (BaseDetailfm)adapter.getItem(position);
				if(position > 0){
					DemoScorllPauseVd demoScorllPauseVd1 = (BaseDetailfm)adapter.getItem(position-1);
					demoScorllPauseVd1.onPauseVideo(dataLv.get(position-1).get(InfoOj.VIDEO_URL));
				}				
				DemoScorllPauseVd demoScorllPauseVd2 = (BaseDetailfm)adapter.getItem(position+1);				
				demoScorllPauseVd2.onPauseVideo(dataLv.get(position+1).get(InfoOj.VIDEO_URL));
				//demoScorllPauseVd.onPauseVideo(dataLv.get(position-1).get(InfoOj.VIDEO_URL));
				// nhu the nay da pause duoc chua? 
			}

			@Override
			public void onPageScrolled(int position, float arg1, int arg2) {
				// TODO Auto-generated method stub
				temcurepare=position;
//				DemoScorllPauseVd demoScorllPauseVd = (BaseDetailfm)adapter.getItem(position);
//				demoScorllPauseVd.onPauseVideo(dataLv.get(position).get(InfoOj.VIDEO_URL));
				
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				Mlog.T("state="+arg0);
				if (arg0 == 1) {
					
					//BaseDetailfm abc = (BaseDetailfm) adapter.getItem(temcurepare);
//					abc.onPauseVideo();
//					Mlog.T("temcure="+temcurepare);
				}
			}
		});

	}

}
